package com.algorithm;

/**
 * @author: sun.hongliang
 * @create: 2019/11/14 18:57
 */
public class MajorityElement {
    public static void main(String[] args) {

    }

    public int majorityElement(int[] nums) {
        int count = 0;
        int majority = -1;
        for (int num : nums) {
            if (count == 0) {
                majority = num;
            }
            count += (majority == num) ? 1 : -1;
        }
        return majority;
    }
}
